package com.heima.wemedia.listener;


import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MqListener {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 监听文章状态信息
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(name = "delay.direct", delayed = "true"),
            value = @Queue(name = "delay.queue"),
            key = "delay"
    ))
    public void WmNewsStatus(String msg) {
        log.info("接收到延迟消息{}", msg);
        WmNews wmNews = wmNewsService.getById(msg);
        wmNews.setStatus((short) 9);
        wmNewsService.updateById(wmNews);
        log.info("人工审核文章已发布");
    }
}
